<template>
  <div class="reportFormPage">
    <div class="report-dom">
      <el-row>
        <el-col :span="5" :offset="19">
          <div class="pageNumBox">
            <span>第</span>
            <span class="placeholder-min text-center">&nbsp;{{ form.page }}&nbsp;</span>
            <span>页，共</span>
            <span class="placeholder-min text-center">&nbsp;{{ form.totalPage }}&nbsp;</span>
            <span>页</span>
          </div>
        </el-col>
      </el-row>
      <div class="topTwoBox">
        <div class="centerName">钢筋焊接接头试验检测记录表</div>
        <div class="codeText">JGLQ15003<br />JGLQ15007</div>
      </div>
      <div class="threeTopBox">
        <div class="left-border">
          <div class="box-title">检测单位名称：</div>
          <div class>{{ form.jiancdwmc }}</div>
        </div>
        <div class="right-border">
          <span>记录编号：</span>
          <span v-if="isPdf" class="placeholder">{{ form.jilbh }}</span>
          <el-input class="code-input" v-else type="text" v-model="form.jilbh" @focus="handleFocus('jilbh')" />
        </div>
      </div>
      <div class="table-border">
        <!------------------------------表头-------------------------->
        <table height="220px" class="top-table">
          <tbody>
            <tr>
              <td height="30" align="center" width="15%">
                <span style="width: 90px; display: inline-block">工程名称</span>
              </td>
              <td width="35%" class="text-center">
                <span>{{ form.gongcmc }}</span>
              </td>
              <td align="center" width="15%">
                <span style="width: 90px; display: inline-block">工程部位/用途</span>
              </td>
              <td width="35%" class="text-center">
                <span>{{ form.gongcbwyt }}</span>
              </td>
            </tr>
            <tr>
              <td height="50" align="center">样品信息</td>
              <td class="specimen-border" colspan="3">
                <span>样品名称：</span>
                <span :class="{ placeholder: !form.yangpmc }">{{ form.yangpmc }}</span>
                <span>；样品编号：</span>
                <span :class="{ 'placeholder-long': !form.yangpbh }">{{ form.yangpbh }}</span>
                <span>；样品数量：</span>
                <span :class="{ placeholder: !form.yangpsl }">{{ form.yangpsl }}</span>
                <span>；样品状态：</span>
                <span :class="{ placeholder: !form.yangpzt }">{{ form.yangpzt }}</span>
                <span>；来样时间：</span>
                <span :class="{ placeholder: !form.yangpsj }">{{ form.yangpsj }}</span>
              </td>
            </tr>

            <tr>
              <td height="25" align="center" width="15%">
                <span style="width: 90px; display: inline-block">试验检测日期</span>
              </td>
               <!-- <td width="35%" class="text-center">{{ form.shiyjcrq }}</td> -->                                            
 <td width="35%" class="text-center">
      <el-input v-model="form.shiyjcrq" />
</td>
              <td align="center" width="15%">
                <span style="width: 90px; display: inline-block">试验条件</span>
              </td>
              <td v-if="isPdf" width="35%">
                温度：
                <span style="display: inline-block; width: 10%">{{ form.shiytjwd }}</span>
                ℃；湿度：
                <span style="display: inline-block; width: 10%">{{ form.shiytjsd }}</span
                >%RH
              </td>
              <td v-else width="35%">
                温度：
                <el-input :type="isPdf ? 'string' : 'number'" v-model="form.shiytjwd" style="width: 15%" />℃；湿度：
                <el-input :type="isPdf ? 'string' : 'number'" v-model="form.shiytjsd" style="width: 15%" />%RH
              </td>
            </tr>

            <tr>
              <td height="50" align="center" width="15%">
                <span style="width: 90px; display: inline-block">检测依据</span>
              </td>
              <td width="35%">
                <span v-if="isPdf">{{ form.jiancyj }}</span>
                <el-input v-else type="textarea" v-model="form.jiancyj" :rows="2" class="mark" @dblclick.native="showBsJiancyjView" readonly />
              </td>
              <td align="center" width="15%">
                <span style="width: 90px; display: inline-block">判定依据</span>
              </td>
              <td width="35%">
                <span v-if="isPdf">{{ form.pandyj }}</span>
                <el-input v-else type="textarea" v-model="form.pandyj" :rows="2" @dblclick.native="showBsJudgeBaseView" @focus="handleFocus('pandyj')" class="mark" />
              </td>
            </tr>
            <tr class="bottom-border">
              <td height="50" align="center">
                <div>主要仪器设备</div>
                <div>名称及编号</div>
              </td>
              <td colspan="3">
                <span v-if="isPdf">{{ form.zhuyyqsbmcjbh }}</span>
                <el-input v-else type="textarea" :rows="2" v-model="form.zhuyyqsbmcjbh" class="height100 width100 mark" @dblclick.native="showBsInstrumentView" readonly></el-input>
              </td>
            </tr>
          </tbody>
        </table>
        <!------------------------------表中-------------------------->
        <table height="616px" class="middle-table">
          <tbody>
            <tr height="25">
              <td>生产厂家</td>
              <td colspan="3"><el-input type="text" v-model="form.cd" @keydown.native="handleKeyDown($event, 0, 0)" :ref="'0_0'" /></td>
              <td>代表数量</td>
              <td colspan="3"><el-input type="text" v-model="form.daibsl" @keydown.native="handleKeyDown($event, 0, 1)" :ref="'0_1'" /></td>
            </tr>
            <tr height="25">
              <td>进场日期</td>
              <td colspan="3"><el-input type="text" v-model="form.jincrq" @keydown.native="handleKeyDown($event, 1, 0)" :ref="'1_0'" /></td>
              <td>批号</td>
              <td colspan="3"><el-input type="text" v-model="form.pih" @keydown.native="handleKeyDown($event, 1, 1)" :ref="'1_1'" /></td>
            </tr>
            <tr height="25">
              <td colspan="2">焊接种类</td>
              <td colspan="3"><el-input type="text" v-model="form.detailList[0].hanjzl" @keydown.native="handleKeyDown($event, 2, 0)" :ref="'2_0'" /></td>
              <td colspan="3"><el-input type="text" v-model="form.detailList[3].hanjzl" @keydown.native="handleKeyDown($event, 2, 1)" :ref="'2_1'" /></td>
            </tr>
            <tr height="25">
              <td colspan="2">钢筋牌号</td>
              <td colspan="3"><el-input type="text" v-model="form.detailList[0].gangjph" @keydown.native="handleKeyDown($event, 3, 0)" :ref="'3_0'" /></td>
              <td colspan="3"><el-input type="text" v-model="form.detailList[3].gangjph" @keydown.native="handleKeyDown($event, 3, 1)" :ref="'3_1'" /></td>
            </tr>
            <tr height="25">
              <td colspan="2">试件编号</td>
              <td><el-input type="text" v-model="form.detailList[0].shijbh" @keydown.native="handleKeyDown($event, 4, 0)" :ref="'4_0'" /></td>
              <td><el-input type="text" v-model="form.detailList[1].shijbh" @keydown.native="handleKeyDown($event, 4, 1)" :ref="'4_1'" /></td>
              <td><el-input type="text" v-model="form.detailList[2].shijbh" @keydown.native="handleKeyDown($event, 4, 2)" :ref="'4_2'" /></td>
              <td><el-input type="text" v-model="form.detailList[3].shijbh" @keydown.native="handleKeyDown($event, 4, 3)" :ref="'4_3'" /></td>
              <td><el-input type="text" v-model="form.detailList[4].shijbh" @keydown.native="handleKeyDown($event, 4, 4)" :ref="'4_4'" /></td>
              <td><el-input type="text" v-model="form.detailList[5].shijbh" @keydown.native="handleKeyDown($event, 4, 5)" :ref="'4_5'" /></td>
            </tr>
            <tr height="25">
              <td width="15%" rowspan="3">试件尺寸</td>
              <td width="15%">直径(mm)</td>
              <td colspan="3"><el-input type="number" v-model="form.detailList[0].zhij" @keydown.native="handleKeyDown($event, 5, 0)" :ref="'5_0'" @change="countGangjjmj(0)" /></td>
              <td colspan="3"><el-input type="number" v-model="form.detailList[3].zhij" @keydown.native="handleKeyDown($event, 5, 1)" :ref="'5_1'" @change="countGangjjmj(3)" /></td>
            </tr>
            <tr height="25">
              <td>焊接长度(mm)</td>
              <td style="width: calc(70% / 6 * 1)"><el-input type="number" v-model="form.detailList[0].hanjcd" @keydown.native="handleKeyDown($event, 6, 0)" :ref="'6_0'" /></td>
              <td style="width: calc(70% / 6 * 1)"><el-input type="number" v-model="form.detailList[1].hanjcd" @keydown.native="handleKeyDown($event, 6, 1)" :ref="'6_1'" /></td>
              <td style="width: calc(70% / 6 * 1)"><el-input type="number" v-model="form.detailList[2].hanjcd" @keydown.native="handleKeyDown($event, 6, 2)" :ref="'6_2'" /></td>
              <td style="width: calc(70% / 6 * 1)"><el-input type="number" v-model="form.detailList[3].hanjcd" @keydown.native="handleKeyDown($event, 6, 3)" :ref="'6_3'" /></td>
              <td style="width: calc(70% / 6 * 1)"><el-input type="number" v-model="form.detailList[4].hanjcd" @keydown.native="handleKeyDown($event, 6, 4)" :ref="'6_4'" /></td>
              <td style="width: calc(70% / 6 * 1)"><el-input type="number" v-model="form.detailList[5].hanjcd" @keydown.native="handleKeyDown($event, 6, 5)" :ref="'6_5'" /></td>
            </tr>
            <tr height="25">
              <td>钢筋截面积(mm²)</td>
              <td colspan="3"><el-input type="number" v-model="form.detailList[0].gangjjmj" disabled /></td>
              <td colspan="3"><el-input type="number" v-model="form.detailList[3].gangjjmj" disabled /></td>
            </tr>
            <tr height="25">
              <td colspan="2">极限荷载(kN)</td>
              <td><el-input type="number" v-model="form.detailList[0].jixhz" @change="countJixqd(0, 0)" @keydown.native="handleKeyDown($event, 7, 0)" :ref="'7_0'" /></td>
              <td><el-input type="number" v-model="form.detailList[1].jixhz" @change="countJixqd(1, 0)" @keydown.native="handleKeyDown($event, 7, 1)" :ref="'7_1'" /></td>
              <td><el-input type="number" v-model="form.detailList[2].jixhz" @change="countJixqd(2, 0)" @keydown.native="handleKeyDown($event, 7, 2)" :ref="'7_2'" /></td>
              <td><el-input type="number" v-model="form.detailList[3].jixhz" @change="countJixqd(3, 3)" @keydown.native="handleKeyDown($event, 7, 3)" :ref="'7_3'" /></td>
              <td><el-input type="number" v-model="form.detailList[4].jixhz" @change="countJixqd(4, 3)" @keydown.native="handleKeyDown($event, 7, 4)" :ref="'7_4'" /></td>
              <td><el-input type="number" v-model="form.detailList[5].jixhz" @change="countJixqd(5, 3)" @keydown.native="handleKeyDown($event, 7, 5)" :ref="'7_5'" /></td>
            </tr>
            <tr height="25">
              <td colspan="2">极限强度(MPa)</td>
              <td><el-input type="number" v-model="form.detailList[0].jixqd" disabled /></td>
              <td><el-input type="number" v-model="form.detailList[1].jixqd" disabled /></td>
              <td><el-input type="number" v-model="form.detailList[2].jixqd" disabled /></td>
              <td><el-input type="number" v-model="form.detailList[3].jixqd" disabled /></td>
              <td><el-input type="number" v-model="form.detailList[4].jixqd" disabled /></td>
              <td><el-input type="number" v-model="form.detailList[5].jixqd" disabled /></td>
            </tr>
            <tr height="25">
              <td colspan="2">断口型式</td>
              <td><el-input type="text" v-model="form.detailList[0].duankxs" @keydown.native="handleKeyDown($event, 8, 0)" :ref="'8_0'" /></td>
              <td><el-input type="text" v-model="form.detailList[1].duankxs" @keydown.native="handleKeyDown($event, 8, 1)" :ref="'8_1'" /></td>
              <td><el-input type="text" v-model="form.detailList[2].duankxs" @keydown.native="handleKeyDown($event, 8, 2)" :ref="'8_2'" /></td>
              <td><el-input type="text" v-model="form.detailList[3].duankxs" @keydown.native="handleKeyDown($event, 8, 3)" :ref="'8_3'" /></td>
              <td><el-input type="text" v-model="form.detailList[4].duankxs" @keydown.native="handleKeyDown($event, 8, 4)" :ref="'8_4'" /></td>
              <td><el-input type="text" v-model="form.detailList[5].duankxs" @keydown.native="handleKeyDown($event, 8, 5)" :ref="'8_5'" /></td>
            </tr>
            <tr height="25">
              <td colspan="2">断口离焊口距离(mm)</td>
              <td><el-input type="number" v-model="form.detailList[0].duanklhkjl" @keydown.native="handleKeyDown($event, 9, 0)" :ref="'9_0'" /></td>
              <td><el-input type="number" v-model="form.detailList[1].duanklhkjl" @keydown.native="handleKeyDown($event, 9, 1)" :ref="'9_1'" /></td>
              <td><el-input type="number" v-model="form.detailList[2].duanklhkjl" @keydown.native="handleKeyDown($event, 9, 2)" :ref="'9_2'" /></td>
              <td><el-input type="number" v-model="form.detailList[3].duanklhkjl" @keydown.native="handleKeyDown($event, 9, 3)" :ref="'9_3'" /></td>
              <td><el-input type="number" v-model="form.detailList[4].duanklhkjl" @keydown.native="handleKeyDown($event, 9, 4)" :ref="'9_4'" /></td>
              <td><el-input type="number" v-model="form.detailList[5].duanklhkjl" @keydown.native="handleKeyDown($event, 9, 5)" :ref="'9_5'" /></td>
            </tr>
            <tr height="25">
              <td rowspan="3">弯曲</td>
              <td>压头直径(mm)</td>
              <td><el-input type="number" v-model="form.detailList[0].yatzj" disabled /></td>
              <td><el-input type="number" v-model="form.detailList[1].yatzj" disabled /></td>
              <td><el-input type="number" v-model="form.detailList[2].yatzj" disabled /></td>
              <td><el-input type="number" v-model="form.detailList[3].yatzj" disabled /></td>
              <td><el-input type="number" v-model="form.detailList[4].yatzj" disabled /></td>
              <td><el-input type="number" v-model="form.detailList[5].yatzj" disabled /></td>
            </tr>
            <tr height="25">
              <td>弯曲角度(°)</td>
              <td><el-input type="number" v-model="form.detailList[0].wanqjd" @keydown.native="handleKeyDown($event, 10, 0)" :ref="'10_0'" @change="countGangjjmjOld(0, 0)" /></td>
              <td><el-input type="number" v-model="form.detailList[1].wanqjd" @keydown.native="handleKeyDown($event, 10, 1)" :ref="'10_1'" @change="countGangjjmjOld(0, 1)" /></td>
              <td><el-input type="number" v-model="form.detailList[2].wanqjd" @keydown.native="handleKeyDown($event, 10, 2)" :ref="'10_2'" @change="countGangjjmjOld(0, 2)" /></td>
              <td><el-input type="number" v-model="form.detailList[3].wanqjd" @keydown.native="handleKeyDown($event, 10, 3)" :ref="'10_3'" @change="countGangjjmjOld(3, 3)" /></td>
              <td><el-input type="number" v-model="form.detailList[4].wanqjd" @keydown.native="handleKeyDown($event, 10, 4)" :ref="'10_4'" @change="countGangjjmjOld(3, 4)" /></td>
              <td><el-input type="number" v-model="form.detailList[5].wanqjd" @keydown.native="handleKeyDown($event, 10, 5)" :ref="'10_5'" @change="countGangjjmjOld(3, 5)" /></td>
            </tr>
            <tr height="25">
              <td>试验结果</td>
              <td><el-input type="text" v-model="form.detailList[0].shiyjg" @keydown.native="handleKeyDown($event, 11, 0)" :ref="'11_0'" /></td>
              <td><el-input type="text" v-model="form.detailList[1].shiyjg" @keydown.native="handleKeyDown($event, 11, 1)" :ref="'11_1'" /></td>
              <td><el-input type="text" v-model="form.detailList[2].shiyjg" @keydown.native="handleKeyDown($event, 11, 2)" :ref="'11_2'" /></td>
              <td><el-input type="text" v-model="form.detailList[3].shiyjg" @keydown.native="handleKeyDown($event, 11, 3)" :ref="'11_3'" /></td>
              <td><el-input type="text" v-model="form.detailList[4].shiyjg" @keydown.native="handleKeyDown($event, 11, 4)" :ref="'11_4'" /></td>
              <td><el-input type="text" v-model="form.detailList[5].shiyjg" @keydown.native="handleKeyDown($event, 11, 5)" :ref="'11_5'" /></td>
            </tr>
            <tr height="25">
              <td colspan="2">焊接质量评述</td>
              <td colspan="3"><el-input type="text" v-model="form.detailList[0].hanjzlps" @keydown.native="handleKeyDown($event, 12, 0)" :ref="'12_0'" /></td>
              <td colspan="3"><el-input type="text" v-model="form.detailList[3].hanjzlps" @keydown.native="handleKeyDown($event, 12, 1)" :ref="'12_1'" /></td>
            </tr>
          </tbody>
        </table>
        <!------------------------------附加声明-------------------------->
        <table height="30px" class="bottom-table">
          <tr>
            <td>
              <span v-if="isPdf" class="textarea-span">{{ form.fujsm }}</span>
              <el-input v-else type="textarea" :rows="2" v-model="form.fujsm" @focus="handleFocus('fujsm')" />
            </td>
          </tr>
        </table>
      </div>
      <!------------------------------表底-------------------------->
      <table height="22px" class="transparent">
        <tr>
          <td width="10%" align="right">检测：</td>
          <td width="15%" align="left"></td>
          <td width="10%" align="right">记录：</td>
          <td width="15%" align="left"></td>
          <td width="10%" align="right">复核：</td>
          <td align="left" width="15%"></td>
          <td width="10%">日期：</td>
          <td align="left" width="15%"></td>
        </tr>
      </table>
    </div>
    <bs-instrument-view ref="bsInstrumentViewRef" @select="selectInstrument"></bs-instrument-view>
    <bs-jiancyj-view ref="bsJiancyjViewRef" @select="selectJiancyj" :syType="syType"></bs-jiancyj-view>
    <bs-judge-base-view ref="bsJudgeBaseViewRef" @select="selectJudge" :syType="syType"></bs-judge-base-view>
  </div>
</template>

<script>
import { listGjhjjtjlbBsInfo, getGjhjjtjlbBsInfo, delGjhjjtjlbBsInfo, addGjhjjtjlbBsInfo, updateGjhjjtjlbBsInfo } from "@/api/report_gc/gjhjjtjlbBsInfo";
import BsInstrumentView from "@/views/dept/bsInstrument/BsInstrumentView.vue";
import decimal from "@/utils/big-decimal";
import BsJiancyjView from "@/views/sycs/bsJiancyj/BsJiancyjView";
import BsJudgeBaseView from "@/views/sycs/bsJudgeBase/BsJudgeBaseView";
import { handleFocus, handleKeyDown } from "@/views/reportForms/utils";
import Bus from "@/utils/bus";

export default {
  name: "gjhjjtjlb",
  components: {
    BsInstrumentView,
    BsJiancyjView,
    BsJudgeBaseView
  },
  props: {
    excelId: {
      type: [String, Number],
      default: () => ""
    },
    syType: {
      type: [String, Number],
      default: () => ""
    },
    page: {
      type: Number,
      default: () => 0
    },
    isPdf: {
      type: Boolean,
      default: () => false
    }
  },
  data() {
    return {
      params: {},
      query: {},
      // 表单参数
      form: {
        detailList: [{}, {}, {}, {}, {}, {}]
      },
      // 表单校验
      rules: {
        excelId: [{ required: true, message: "主键不能为空", trigger: "blur" }]
      },
      jmjObj: {
        0: 0,
        3: 0
      } // 截面积真实值
    };
  },
  watch: {
    // form: "busForm"
    form: {
      handler: function (newValue, oldValue) {
        Bus.$emit("setGcHjjtForm", newValue);
      },
      deep: true,
      immediate: true
    }
  },
  created() {
    this.getInfo();
  },
  methods: {
    // 获取详情
    getInfo() {
      getGjhjjtjlbBsInfo(this.excelId).then((response) => {
        this.form = response.data;
        if (!this.form.fujsm) {
          this.form.fujsm = "附加声明：";
        }
      });
    },

    // 显示检测依据列表
    showBsJiancyjView() {
      this.$refs.bsJiancyjViewRef.init(this.form.jiancyjIds);
    },
    // 检测依据选择
    selectJiancyj(info) {
      this.form.jiancyj = info.label;
      this.form.jiancyjIds = info.ids;
      Bus.$emit("setGjhjjtBgJiancyj", { jiancyj: this.form.jiancyj, jiancyjIds: this.form.jiancyjIds });
    },

    // 显示判定依据列表
    showBsJudgeBaseView() {
      this.$refs.bsJudgeBaseViewRef.init(this.form.pandyjIds);
    },
    // 判断依据选择
    selectJudge(info) {
       this.form.pandyjIds = info.ids;
      this.form.pandyj = info.label;
    },

    // 显示仪器列表
    showBsInstrumentView() {
      this.$refs.bsInstrumentViewRef.init(this.form.shebIds);
    },
    // 仪器选择
    selectInstrument(info) {
      this.form.zhuyyqsbmcjbh = info.label;
      this.form.shebIds = info.ids;
      Bus.$emit("setGjhjjtBgZhuyyqsbmcjbh", { zhuyyqsbmcjbh: this.form.zhuyyqsbmcjbh, shebIds: this.form.shebIds });
    },

    handleFocus(event) {
      handleFocus(event, this.page, this.form[event]);
    },
    countGangjjmjOld(num, num2) {
      let A = Number(this.form.detailList[num].zhij) || 0;
      if (this.form.detailList[num2].wanqjd) {
        this.form.detailList[num2].yatzj = decimal.round(4 * A, 1) || 0;
      } else {
        this.form.detailList[num2].yatzj = null;
      }
    },
    countGangjjmj(num) {
      let A = Number(this.form.detailList[num].zhij) || 0;
      let B = A / 2; //半径
      let C = B * B * 3.1415926;
      this.jmjObj[num] = C;
      this.form.detailList[num].gangjjmj = decimal.round(C, 1) || 0;
    },
    countJixqd(num, setNum) {
      let A = Number(this.form.detailList[num].jixhz) || 0;
      let B = this.jmjObj[setNum];
      let C = (A * 1000) / B;
      let D = Math.ceil(C / 5) * 5;
      this.form.detailList[num].jixqd = D;
    },
    submitForm() {
      return this.form;
    },
    handleKeyDown(event, rowIndex, colIndex) {
      const maxArr = [1, 1, 1, 1, 5, 1, 5, 5, 5, 5, 5, 5, 1]; // 每一行最多有多少可聚焦输入框（从0开始）
      const ref = handleKeyDown(event, rowIndex, colIndex, maxArr);
      if (this.$refs[ref]) {
        this.$refs[ref].focus();
      }
    }
  }
};
</script>


<style scoped></style>
